
//const API_HEAD =  '/backend/' 
    //Constant.SWITCH_VCONSOLE?'https://bwv.net.cn':'/backend/'
   

  //   var GetQueryString =(name,content)=>{
  //     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  //     var r = content.substr(1).match(reg);
  //     if(r!=null)return unescape(r[2]); return 'null';
  // };

  const API_HEAD = `https://techcherry.cn/playwithapi/`;

  var GetQueryString =(name)=>{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return unescape(r[2]); return 'null';
};

var decodeurl =(str)=>{
  var s = "";
  if (str.length == 0) return "";
  s = str.replace(/&amp;/g, "&");
  s = s.replace(/&lt;/g, "<");
  s = s.replace(/&gt;/g, ">");
  s = s.replace(/&nbsp;/g, " ");
  s = s.replace(/&#39;/g, "\'");
  s = s.replace(/&quot;/g, "\"");
  return s;  
}


var isBase64=(str)=>
 {
 return str.indexOf('data:image')>-1; 
}

//去重
var uniq=(array)=>{
 
  var temp = []; //一个新的临时数组
  array.forEach(x=>{
    if(temp.indexOf(Number(x) ) == -1)  temp.push(Number(x));
    console.log('uniq',temp);

  })
  
  return temp;
}

var getstatecontent = (state)=>{
  let content = '';
  switch (state) {
      case 'SOLVED':
          content= '已完成';
          break;
      case 'REDEEMED':
          content= '结算';
          break;
      case 'REDEEM':
          content= '赎回待确认';
          break;
      case 'SHARE_SUCCESS':
          content= '待赎回';
          break;
      case 'PAY_SUCCESS':
          content= '份额待确认';
          break;
          
      default:
          break;
  }
  return content;
}
var getstateassemble = (state)=>{
  let content = '';
  switch (state) {
      case 'WAIT':
          content= '未开始';
          break;
      case 'WORKING':
          content= '活动中';
          break;
      case 'END':
          content= '已结束';
          break;
      case 'NOWORK':
          content= '已失效';
          break;   
      default:
          break;
  }
  return content;
}
var getfoodsstateassemble = (state)=>{
  let content = '';
  switch (state) {
      case 'WAIT':
          content= '待审核';
          break;
      case 'SUCCESS':
          content= '成功';
          break;
      case 'FAIL':
          content= '失败';
          break; 
      default:
          break;
  }
  return content;
}
var showAlert = (wrap,content,id,type)=>{
  
  wrap.append(` <div id="${id}" class="alert alert-${type}">
  <a href="#" class="close" data-dismiss="alert">&times;</a>
  <strong>提示！</strong>${content}  </div>`)
  $(`#${id}`).alert();
}

getareaRange =(area)=>{
if (area == -1) {
  
    area= '全区'
  
} else if (area == 0) {
  
    area='1公里'
  
} else if (area == 1) {
  
    area= '1-2公里'
  
} else if (area == 2) {
 
    area= '1-3公里'
  
} else if (area == 3) {
  
    area= '1-4公里'
 
} else if (area == 4) {
  
    area='1-5公里'
  
} else {

}
return area;
}
// var GetQueryString =(name)=>{
//   var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
// return svalue ? svalue[1] : svalue;
// }

var backlogin = (username,password,succ)=>{
  fstHttps(`${API_HEAD}login/bklogin`,{username,password},res=>{
    succ&&succ(res)
  },'POST')
}

var uploadimg = (base64str,succ)=>{
  Https( `${API_HEAD}upload/upload`,{base64str} ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}

// 上传excel
var uploadexcel = (data,succ)=>{
  Https( `${API_HEAD}upload/uploadexcel`,data ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}
// var uploadexcel = (file,succ)=>{
//     var data = new FormData();
//     data.append("token",$.cookie('token'));
//     data.append('file',file)
//     $.ajax({
//       url:`${API_HEAD}upload/uploadexcel`, /*接口域名地址*/
//       type:'post',
//       data,
//       contentType: false,
//           processData: false,
//       success:res=>{
//         succ&&succ(JSON.parse(res))
//         console.log(res,'resres')
//       }
//     })
//   }


//压缩图片
var compressimg = (data,succ)=>{
  Https( `${API_HEAD}upload/upload_imgya`,data,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}



var checklogin = (succ)=>{
  Https(`${API_HEAD}login/check`,{},res=>{
    succ&&succ(res)
  })
}


var checkPhone=(phone)=>{
  var re =/^[1][3,4,5,7,8][0-9]{9}$/;
  return re.test(phone)
}

function isIPhoneX(){
  
  
   if (screen.height == 812 && screen.width == 375){
       //是iphoneX 
       console.log('是iphoneX/XS 系列');
     return true;
     }else{
          //不是iphoneX
          return false; 
         } }


//默认GET方法
var fstHttps =(url,data,succ,type)=>{
  console.log(url,'fsturl');
  
    $.ajax({
            url,
            type:type?type:'GET',
         
            data,
            success: function (res) {
              succ&&succ(res)
            },
        })
}


var Https =(url,data,succ,type,fail,isasync)=>{
  var senddata = { token:$.cookie('token') }
if(!senddata.token) {window.location.href='./docshopunknwo.html';return}
  
   for(var k in data){
     senddata[k] = data[k]
   }
   console.log(senddata,'senddata');
   
    $.ajax({
            url,
            type:type?type:'POST',
            data:senddata,
            async:isasync=='false'?!1:!0,
            // beforeSend:res=>{
            //   res.setRequestHeader("token",$.cookie('token') );
            // },
            success: function (res) {
              succ&&succ(JSON.parse(res))
            },
           
            complete: function (res) {
              if(res.status!=200){
                fail&&fail(res.responseText)
              }
            },
        })
}


var getLocalTime=(nS)=> { 
	//将时间戳（十三位时间搓，也就是带毫秒的时间搓）转换成时间格式
	// d.cTime = 1539083829787
	let date = new Date(nS);
	let year = date.getFullYear();
	let month = date.getMonth()+1;
	let day = date.getDate();
	month = month < 10 ? "0"+month:month;
	day = day < 10 ? "0"+day:day;
	date = year+'/'+month+'/'+day;
	console.log(date); // 2018-10-09
	return date;
} 


var getLocalTime1 = (nS) => {
  //将时间戳（十三位时间搓，也就是带毫秒的时间搓）转换成时间格式
  // d.cTime = 1539083829787
  let date = new Date(nS);
  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  let h = date.getHours();
  let m = date.getMinutes();
  let s = date.getSeconds();
  month = month < 10 ? "0" + month : month;
  day = day < 10 ? "0" + day : day;
  h = h < 10 ? "0" + h : h;
  m = m < 10 ? "0" + m : m;
  s = s < 10 ? "0" + s : s;
  date = year + '-' + month + '-' + day + ' ' + h + ':' + m //+ ':' + s;
  console.log(date); // 2018-10-09
  return date;
}




var formatDate = (date)=>{
 return `${date.getFullYear()}.${date.getMonth()+1}.${date.getDate()} ${date.getHours()>9?date.getHours():"0"+date.getHours()}:${date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes()}`;
}

var formatDate1 = (sd)=>{
  return sd.getFullYear()+"-"+("0" + (sd.getMonth() + 1)).slice(-2)+"-"+("0" + sd.getDate()).slice(-2);
 }
 //参数：numb是excel转换出来的整数值，format是年月日之间分隔符号。
//  使用xlsx.full.min.js 获取excel的日期数据为：37858；
 var xlsxformatDate=(numb, format)=> {
  let time = new Date((numb-2) * 24 * 3600000 + 1)
  time.setYear(time.getFullYear() - 70)
  let year = time.getFullYear() + ''
  let month = time.getMonth() + 1 + ''
  let date = time.getDate() + ''
  if(format && format.length === 1) {
      return year + format + month + format + date
  }
  return year+(month < 10 ? '0' + month : month)+(date < 10 ? '0' + date : date)
}

// liu

// 后台获取轮播图列表
var swipergetlist = (succ) => { 
  Https(`${API_HEAD}swiper/bk_getlist`, {}, res => {
    succ && succ(res)
  }, 'POST')
}

var 获取分类列表 = (type,succ) => { 
  Https(`${API_HEAD}category/bk_getlist`, {type}, res => {
    succ && succ(res)
  }, 'POST')
}

var 添加分类 = (data,succ) => { 
  Https(`${API_HEAD}category/add`, data, res => {
    succ && succ(res)
  }, 'POST')
}
var 分类修改价格 = (data,succ) => { 
  Https(`${API_HEAD}category/bk_setprice`, data, res => {
    succ && succ(res)
  }, 'POST')
}

var 删除分类 = (id,succ) => { 
  Https(`${API_HEAD}category/bk_del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}

var 获取实名认证列表 = (data,succ) => { 
  Https(`${API_HEAD}idv/bk_getlist`,data, res => {
    succ && succ(res)
  }, 'POST')
}

var 实名认证审核 = (data,succ) => { 
  Https(`${API_HEAD}idv/bk_check`,data, res => {
    succ && succ(res)
  }, 'POST')
}
var 实名认证删除 = (id,succ) => { 
  Https(`${API_HEAD}idv/bk_del`,{id}, res => {
    succ && succ(res)
  }, 'POST')
}



// 后台添加/修改轮播图
var swiperaoe = (data, succ) => {
  Https(`${API_HEAD}swiper/bk_aoe`, data, res => {
    succ && succ(res)
  }, 'POST')
}


var swiperdelimg = (id, succ) => {
  Https(`${API_HEAD}swiper/del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}

var swipersetorders = (data,succ)=>{
  Https(`${API_HEAD}swiper/bk_setorder`,data,res=>{
    succ&&succ(res)
  },'POST')
}
var swipersetshow = (id,succ)=>{
  Https(`${API_HEAD}swiper/bk_setshow`,{id},res=>{
    succ&&succ(res)
  },'POST')
}
// 后台添加/修改一级工种
var Worktypeaoe = (data, succ) => {
  Https(`${API_HEAD}Worktype/bk_aoe`, data, res => {
    succ && succ(res)
  }, 'POST')
}

// 获取列表一级工种
var Worktypegetlist = (succ) => {
  Https(`${API_HEAD}Worktype/bk_getlist`, {}, res => {
    succ && succ(res)
  }, 'POST')
}
// 删除一级工种
var Worktypedel = (id,succ) => {
  Https(`${API_HEAD}Worktype/del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 后台添加/修改二级工种
var Worktypesubaoe = (data, succ) => {
  Https(`${API_HEAD}Worktype/bk_subaoe`, data, res => {
    succ && succ(res)
  }, 'POST')
}
// 获取列表二级工种
var Worktypegetlistbycid = (cid,succ) => {
  Https(`${API_HEAD}Worktype/bk_getlistbycid`, {cid}, res => {
    succ && succ(res)
  }, 'POST')
}
// 删除二级工种
var Worktypesubdel = (id,succ) => {
  Https(`${API_HEAD}Worktype/subdel`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}

// 后台添加/修改公司类型
var Companytypeaoe = (data, succ) => {
  Https(`${API_HEAD}Companytype/bk_aoe`, data, res => {
    succ && succ(res)
  }, 'POST')
}

// 获取列表公司类型
var Companytypegetlist = (succ) => {
  Https(`${API_HEAD}Companytype/bk_getlist`, {}, res => {
    succ && succ(res)
  }, 'POST')
}
// 删除公司类型
var WCompanytypedel = (id,succ) => {
  Https(`${API_HEAD}Companytype/del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 劳务保险
var setinsurance = (value,succ) => {
  Https(`${API_HEAD}Base/setinsurance`, {value}, res => {
    succ && succ(res)
  }, 'POST')
}
// 使用指南
var setuseguide = (value,succ) => {
  Https(`${API_HEAD}Base/setuseguide`, {value}, res => {
    succ && succ(res)
  }, 'POST')
}
// 用户协议
var setagreement = (value,succ) => {
  Https(`${API_HEAD}Base/setagreement`, {value}, res => {
    succ && succ(res)
  }, 'POST')
}
// 隐私政策
var setpolicy = (value,succ) => {
  Https(`${API_HEAD}Base/setpolicy`, {value}, res => {
    succ && succ(res)
  }, 'POST')
}
// 操作指引
var setguidelines = (value,succ) => {
  Https(`${API_HEAD}Base/setguidelines`, {value}, res => {
    succ && succ(res)
  }, 'POST')
}

// 获取具体详情
var Settingsgetdetail = (type,succ) => {
  Https(`${API_HEAD}Base/getdetail`, {type}, res => {
    succ && succ(res)
  }, 'POST')
}

// 后台添加/修改一级工种
var Mechanicstypeaoe = (data, succ) => {
  Https(`${API_HEAD}Mechanicstype/bk_aoe`, data, res => {
    succ && succ(res)
  }, 'POST')
}

// 获取列表一级工种
var Mechanicstypegetlist = (succ) => {
  Https(`${API_HEAD}Mechanicstype/bk_getlist`, {}, res => {
    succ && succ(res)
  }, 'POST')
}
// 删除一级工种
var Mechanicstypedel = (id,succ) => {
  Https(`${API_HEAD}Mechanicstype/del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 后台添加/修改二级工种
var Mechanicstypesubaoe = (data, succ) => {
  Https(`${API_HEAD}Mechanicstype/bk_subaoe`, data, res => {
    succ && succ(res)
  }, 'POST')
}
// 获取列表二级工种
var Mechanicstypegetlistbycid = (cid,succ) => {
  Https(`${API_HEAD}Mechanicstype/bk_getlistbycid`, {cid}, res => {
    succ && succ(res)
  }, 'POST')
}
// 删除二级工种
var Mechanicstypesubdel = (id,succ) => {
  Https(`${API_HEAD}Mechanicstype/subdel`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 后台获取列表招工
var Recruitgetlist = (data, succ) => {
  Https(`${API_HEAD}Recruit/bk_getlist`, data, res => {
    succ && succ(res)
  }, 'POST')
}
// 后台审核招工
var Recruitcheck = (data, succ) => {
  Https(`${API_HEAD}Recruit/bk_check`, data, res => {
    succ && succ(res)
  }, 'POST')
}
// 后台删除招工
var Recruitdel = (id, succ) => {
  Https(`${API_HEAD}Recruit/del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 招工详情
var Recruitgetdetail = (id, succ) => {
  Https(`${API_HEAD}Recruit/getdetail`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 招工急聘
var Recruitseturgent = (id, succ) => {
  Https(`${API_HEAD}Recruit/seturgent`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 获取省
var getprovincelist = (succ) => {
  Https(`${API_HEAD}TB_District/getprovincelist`, {}, res => {
    succ && succ(res)
  }, 'POST')
}
// 通过名称获取市
var getcitylistbyname = (name,succ) => {
  Https(`${API_HEAD}TB_District/getcitylistbyname`, {name}, res => {
    succ && succ(res)
  }, 'POST')
}
// 通过名称获取区
var getdistrictlistbyname = (name,succ) => {
  Https(`${API_HEAD}TB_District/getdistrictlistbyname`, {name}, res => {
    succ && succ(res)
  }, 'POST')
}
// 同城五金获取列表
var Hardwaregetlist = (data,succ) => {
  Https(`${API_HEAD}Hardware/bk_getlist`, data, res => {
    succ && succ(res)
  }, 'POST')
}
// 同城五金修改或者新建
var Hardwareaoe = (data,succ) => {
  Https(`${API_HEAD}Hardware/bk_aoe`, data, res => {
    succ && succ(res)
  }, 'POST')
}
// 同城五金删除
var Hardwaredel = (id,succ) => {
  Https(`${API_HEAD}Hardware/del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 同城五金设置显示隐藏
var Hardwaresetshow = (id,succ) => {
  Https(`${API_HEAD}Hardware/bk_setshow`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}
// 新建开户行
var Bankadd = (name,succ) => {
  Https(`${API_HEAD}Bank/add`, {name}, res => {
    succ && succ(res)
  }, 'POST')
}
// 获取列表开户行
var Bankgetlist= (succ) => {
  Https(`${API_HEAD}Bank/getlist`, {}, res => {
    succ && succ(res)
  }, 'POST')
}
// 删除开户行
var Bankdel = (id,succ) => {
  Https(`${API_HEAD}Bank/del`, {id}, res => {
    succ && succ(res)
  }, 'POST')
}





// end liu












var LoginAfter = (succ)=>{

  Https(`${API_HEAD}users/login/after`
  ,JSON.stringify({'data':{'returnProfile':!0}}) ,res=>{
    succ&&succ(res)
  })
}

 



//微信支付
var requestPayment = (data,succ)=>{
  WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
   "appId":data.appid,     //公众号名称，由商户传入     
   "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数     
   "nonceStr":data.nonceStr, //随机串     
   "package":`prepay_id=${data.prepay_id}`,     
   "signType":"MD5",         //微信签名方式：     
   "paySign":data.paySign//微信签名 
},
function(res){

// 使用以上方式判断前端返回,微信团队郑重提示：
      //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
      succ && succ(res)
}); 
  
}










